package com.vdong.restful.controller;

import com.vdong.restful.api.request.CurrencyParamRequest;
import com.vdong.restful.api.request.OrderInformationRequest;
import com.vdong.restful.api.response.Response;
import com.vdong.restful.service.ShipperFunctionService;
import com.vdong.restful.service.TemplateApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("/orderFreight")
public class OrderFreightController {

    @Autowired
    private TemplateApiService templateApiService;
    @Autowired
    private ShipperFunctionService shipperFunctionService;

    /**
     * 运费计算 客户端
     *
     * @param orderInformationRequest
     * @return
     */
    @RequestMapping(value = "/getOneOrderFreightsService.json", method = RequestMethod.POST)
    public Response getOrderFreighsts(@Valid @RequestBody OrderInformationRequest orderInformationRequest,
                                      String key) {

        return templateApiService.freight(orderInformationRequest, key);

    }

    /**
     * 轨迹查询
     * @param currencyParamRequest
     * @return
     */
    @RequestMapping(value = "/getOnetrajectory.json")
    public Response trajectoryQuery(@Validated(CurrencyParamRequest.TrajectoryQuery.class) CurrencyParamRequest currencyParamRequest) {
        return shipperFunctionService.trajectoryQuery(currencyParamRequest.getLogisticsNumber(),
                currencyParamRequest.getShipperId());
    }
}
